package com.fyh.crud.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.fyh.crud.entity.UserEntity;
import com.fyh.crud.service.TestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("test")
public class TestController {

    @Autowired
    private TestService testService;

    /**
     *
     * @param pageSize
     * @param limit
     * @param key
     * @return
     */
    @RequestMapping("list")
    @ResponseBody
    public Map<String,Object> list(@RequestParam(required = false) int pageSize, @RequestParam(required = false)int limit,
                                   @RequestParam(required = false)String key){
        Map<String,Object> map =new HashMap<>();
        IPage<UserEntity> list=testService.list(pageSize,limit,key);
        map.put("list",list);
        return map;
    }

    @RequestMapping("listAll")
    @ResponseBody
    public Map<String,Object> listAll(){
        Map<String,Object> map =new HashMap<>();
        List<UserEntity> list=testService.listAll();
        map.put("list",list);
        return map;
    }
}
